package com.ruoyi.apm.dao;

import com.ruoyi.apm.model.DockDataConfig;
import com.ruoyi.apm.model.HttpSequence;
import com.ruoyi.apm.model.HttpSystem;
import org.apache.ibatis.annotations.*;

import java.util.List;
import java.util.Map;

@Mapper
public interface DockDataConfigMapper {

	@Insert("INSERT INTO dock_data_config(`table_name`,`data_source`,`mapping_relation`,`field_upper`,`batch_limit`,`is_while`,`while_rule`,`is_clean`,`clean_rule`,`cron`,`guid`,`insert_time`)  VALUES("
			+"#{dockDataConfig.tableName},#{dockDataConfig.dataSource},#{dockDataConfig.mappingRelation},#{dockDataConfig.fieldUpper},#{dockDataConfig.batchLimit},"
			+ "#{dockDataConfig.isWhile},#{dockDataConfig.whileRule},#{dockDataConfig.isClean},#{dockDataConfig.cleanRule},#{dockDataConfig.cron},#{dockDataConfig.guid},now())")
	void insert(@Param("dockDataConfig") DockDataConfig dockDataConfig);

	@Update("update dock_data_config t set `table_name`=#{dockDataConfig.tableName},`data_source`=#{dockDataConfig.dataSource},`mapping_relation`=#{dockDataConfig.mappingRelation},`field_upper`=#{dockDataConfig.fieldUpper}," +
			"`batch_limit`=#{dockDataConfig.batchLimit},`is_while`=#{dockDataConfig.isWhile},`while_rule`=#{dockDataConfig.whileRule}," +
			"`is_clean`=#{dockDataConfig.isClean},`clean_rule`=#{dockDataConfig.cleanRule},`cron`=#{dockDataConfig.cron},`update_time`=now() WHERE t.`guid`= #{dockDataConfig.guid}")
	void update(@Param("dockDataConfig") DockDataConfig dockDataConfig);


	@Select("SELECT id,`table_name` tableName,`data_source` dataSource,`mapping_relation` mappingRelation,`field_upper` fieldUpper,`batch_limit` batchLimit,`is_while` isWhile,`while_rule` whileRule,`is_clean` isClean,`clean_rule` cleanRule,`cron`,`guid` FROM dock_data_config")
	List<DockDataConfig> selectAll();

	@Select("select id,`table_name` tableName,`data_source` dataSource,`mapping_relation` mappingRelation,`field_upper` fieldUpper,`batch_limit` batchLimit,`is_while` isWhile,`while_rule` whileRule,`is_clean` isClean,`clean_rule` cleanRule,`cron`,`guid` from dock_data_config where guid=#{guid}")
	DockDataConfig getByGuid(@Param("guid") String guid);
	
	
	@Select("select date_format(DATE_ADD(now(), INTERVAL #{step} ${unit}),#{format}) value")
	public Map<String,String> getFormatDate(@Param("format")String format,@Param("unit")String unit,@Param("step")Integer step);

	@Select("<script>" +
			"select cron,guid from dock_data_config where guid in <foreach collection=\"guids\" item=\"item\" separator=\",\" open=\"(\" close=\")\">#{item}</foreach>" +
			"</script>")
	public List<DockDataConfig> getDockDataConfigByGuids(@Param("guids")List<String> guids);
}
